import json

from api.base_service import BaseService


class MemberService(BaseService):
    def __init__(self):
        super().__init__()
        self.service_name = "MemberService"
    def find_by_telephone(self,mobile):
        resp = self.dubbo_client.invoke(self.service_name, "findByTelephone",mobile)
        return json.loads(resp)
    def add(self,member):
        member["class"] = "com.itheima.pojo.Member"
        resp = self.dubbo_client.invoke(self.service_name, "add",member)
        if resp == "null":
            return True
        else:
            return False
    def find_member_count_by_months(self,month):
        resp = self.dubbo_client.invoke(self.service_name,"findMemberCountByMonths",month)
        return json.loads(resp)

if __name__ == '__main__':
    mc = MemberService()
    member = {
                    "name":"xiaowang",
                    "phoneNumber": "18210666660",
                    "password": "123456",
                    "birthday": "1990-01-01 10:01:01",
                    "regTime": "2020-01-01 10:01:01"
                }
    result = mc.add(member)
    print(result)
    result_1 = mc.find_member_count_by_months(["2020-01","2022-02"])
    print(result_1)